package com.ruoyi.st.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Collections;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.config.response.StatusCode;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.st.domain.query.PerfDetailDateQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.st.mapper.StPerfDetailMapper;
import com.ruoyi.st.domain.StPerfDetail;
import com.ruoyi.st.service.IStPerfDetailService;

/**
 * 演出详情Service业务层处理
 *
 * @author ruoyi
 * @date 2024-11-14
 */
@Slf4j
@Service
public class StPerfDetailServiceImpl implements IStPerfDetailService
{
    @Autowired
    private StPerfDetailMapper stPerfDetailMapper;
 private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    /**
     * 查询演出详情
     *
     * @param id 演出详情主键
     * @return 演出详情
     */
    @Override
    public StPerfDetail selectStPerfDetailById(Long id)
    {
        return stPerfDetailMapper.selectStPerfDetailById(id);
    }

    /**
     * 查询演出详情列表
     *
     * @param stPerfDetail 演出详情
     * @return 演出详情
     */
    @Override
    public List<StPerfDetail> selectStPerfDetailList(StPerfDetail stPerfDetail)
    {
        return stPerfDetailMapper.selectStPerfDetailList(stPerfDetail);
    }


    /**
     * 新增演出详情
     *
     * @param stPerfDetail 演出详情
     * @return 结果
     */
    @Override
    public int insertStPerfDetail(StPerfDetail stPerfDetail)
    {
        stPerfDetail.setCreateTime(DateUtils.getNowDate());
        return stPerfDetailMapper.insertStPerfDetail(stPerfDetail);
    }

    /**
     * 修改演出详情
     *
     * @param stPerfDetail 演出详情
     * @return 结果
     */
    @Override
    public int updateStPerfDetail(StPerfDetail stPerfDetail)
    {
        stPerfDetail.setUpdateTime(DateUtils.getNowDate());
        return stPerfDetailMapper.updateStPerfDetail(stPerfDetail);
    }

    /**
     * 批量删除演出详情
     *
     * @param ids 需要删除的演出详情主键
     * @return 结果
     */
    @Override
    public int deleteStPerfDetailByIds(Long[] ids)
    {
        return stPerfDetailMapper.deleteStPerfDetailByIds(ids);
    }

    /**
     * 删除演出详情信息
     *
     * @param id 演出详情主键
     * @return 结果
     */
    @Override
    public int deleteStPerfDetailById(Long id)
    {
        return stPerfDetailMapper.deleteStPerfDetailById(id);
    }

    /**
     *  升序排列
     * @param stPerfDetail
     * @return
     */

    @Override
    public List<StPerfDetail> selectStPerfDetailListAsc(StPerfDetail stPerfDetail) {
       return stPerfDetailMapper.selectStPerfDetailListAsc(stPerfDetail);
    }

    /**
     * 降序排列
     * @param stPerfDetail
     * @return
     */

    @Override
    public List<StPerfDetail> selectStPerfDetailListDesc(StPerfDetail stPerfDetail) {
          return stPerfDetailMapper.selectStPerfDetailListDesc(stPerfDetail);
    }

    @Override
    public List<StPerfDetail> selectListByPerfDate(PerfDetailDateQuery perfDetailDateQuery) {
        String perfStartTimeWithTime = perfDetailDateQuery.getPerfStartTime() + " 00:00:00";
         String perfEndTimeWithTime  = perfDetailDateQuery.getPerfEndTime() + " 00:00:00";
         log.debug("开始时间：" + perfDetailDateQuery.getPerfStartTime() + "结束时间：" + perfDetailDateQuery.getPerfEndTime());
        try {
            Date perfStartTime = dateFormat.parse(perfStartTimeWithTime);
            Date perfEndTime = dateFormat.parse(perfEndTimeWithTime);
              Calendar calendar = Calendar.getInstance();
            calendar.setTime(perfEndTime);
            calendar.add(Calendar.DATE, 1);
            perfEndTime = calendar.getTime();
            log.debug("开始时间：" + perfStartTime + "结束时间：" + perfEndTime);
               List<StPerfDetail> selectDateList = stPerfDetailMapper.selectListByPerfDate(perfStartTime,perfEndTime);
               log.debug("查询结果：" + selectDateList);
          return selectDateList;
        } catch (ParseException e) {
           throw new ServiceException(StatusCode.OPERATION_FAILED);
        }


    }

    /**
     * 根据日期查询演出详情
     * @param perfStartTime
     * @param perfEndTime
     * @return
     */

}
